package com.gaofeng.day07;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

public class demo4 {
    public static void main(String[] args) {
        // 创建一个hashMap的对象
        HashMap<Student, String> hm = new HashMap<>();

        //创建3个学生对象
        Student stu1 = new Student("张三", 20);
        Student stu2 = new Student("李四", 21);
        Student stu3 = new Student("王五", 26);


        //将学生对象存储到hashMap中
        hm.put(stu1,"江苏");

        hm.put(stu2,"北京");

        hm.put(stu3,"上海");
        System.out.println(hm);
        //遍历hashMap
        Set<Student> keys = hm.keySet();

        //迭代keys
        for (Student student : keys) {
            System.out.println("5555");
            //通过迭代出来的学生对象，调用hashMap的get方法，得到对应的值

            String value = hm.get(student);

            System.out.println(student+"="+value);
        }

        HashMap<Integer, String> Sites = new HashMap<>();
        // 添加键值对
        Sites.put(1, "Google");
        Sites.put(2, "Runoob");
        Sites.put(3, "Taobao");
        Sites.put(4, "Zhihu");
        System.out.println(Sites);

        Set<Map.Entry<Integer, String>> entries = Sites.entrySet();
        System.out.println(entries);
        // lambda遍历entries

        Sites.forEach((key, value) -> System.out.println("Key = " + key + ", Value = " + value));


        Collection<String> values = Sites.values();

        values.forEach((value) -> System.out.println("Value = " + value));
    }
}
